package skin

import (
	"context"
	"encoding/json"
	"group-card/common/response"
	"group-card/rpc/card/cardclient"

	"group-card/api/internal/svc"
	"group-card/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type SkinDeleteLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSkinDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SkinDeleteLogic {
	return &SkinDeleteLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SkinDeleteLogic) SkinDelete(req *types.DeleteSkinRequest) (resp *types.SkinResponse, err error) {
	_, err = l.svcCtx.Card.SkinDelete(l.ctx, &cardclient.SkinDeleteRequest{
		Id: req.Id,
	})

	if err != nil {
		reqStr, _ := json.Marshal(req)
		logx.WithContext(l.ctx).Errorf("删除卡面失败,参数:%s,异常:%s", reqStr, err.Error())
		return &types.SkinResponse{Code: response.ErrCode, Message: "删除卡面失败"}, nil
	}

	return &types.SkinResponse{
		Code:    response.SuccessCode,
		Message: "删除卡面成功",
	}, nil

	return
}
